package com.acmetelecom.utils;

import java.math.BigDecimal;

import com.acmetelecom.customer.Customer;

public class HtmlPrinter implements Printer {
	public void printHeading(String name, String phoneNumber, String pricePlan) {
		beginHtml();
		System.out.println(h2(name + "/" + phoneNumber + " - " + "Price Plan: "
				+ pricePlan));
		beginTable();
	}

	protected void beginTable() {
		System.out.println("<table border=\"1\">");
		System.out.println(tr(th("Time") + th("Number") + th("Duration")
				+ th("Cost")));
	}

	protected void endTable() {
		System.out.println("</table>");
	}

	protected String h2(String text) {
		return "<h2>" + text + "</h2>";
	}

	public void printItem(String time, Customer callee, String duration,
			BigDecimal cost) {
		System.out.println(tr(td(time) + td(callee.getPhoneNumber())
				+ td(duration) + td(MoneyFormatter.penceToPounds(cost))));
	}

	protected String tr(String text) {
		return "<tr>" + text + "</tr>";
	}

	protected String th(String text) {
		return "<th width=\"160\">" + text + "</th>";
	}

	protected String td(String text) {
		return "<td>" + text + "</td>";
	}

	public void printTotal(BigDecimal total) {
		endTable();
		System.out.println(h2("Total: " + MoneyFormatter.penceToPounds(total)));
		endHtml();
	}

	protected void beginHtml() {
		System.out.println("<html>");
		System.out.println("<head></head>");
		System.out.println("<body>");
		System.out.println("<h1>");
		System.out.println("Acme Telecom");
		System.out.println("</h1>");
	}

	protected void endHtml() {
		System.out.println("</body>");
		System.out.println("</html>");
	}
}
